package main.nonphysical

import main.models.AbstractEntity
import main.person.Person
import main.state.{State, StateLens}

case class Relationship(personLens: StateLens[Person], relationshipType: RelationshipType) extends AbstractEntity

object Relationship {
  def apply(implicit state: State, personALens: StateLens[Person], personBLens: StateLens[Person], relationshipType: RelationshipType): State = {
    val (relationshipALens, updated1State) = state.registerEntity(new Relationship(personBLens, relationshipType))
    val (relationshipBLens, updated2State) = updated1State.registerEntity(new Relationship(personALens, relationshipType))
    val updated3State = personALens.addChild(updated2State, relationshipALens)
    personBLens.addChild(updated3State, relationshipBLens)
  }
}
